package daoBDDImpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import utils.HibernateUtil;
import bean.Sport;
import dao.SportDao;

public class SportDaoBDDImpl extends HibernateDaoSupport implements SportDao {

	public SportDaoBDDImpl(){
		super();
		setSessionFactory(HibernateUtil.getSessionFactory());
	}
	
	@Override
	public Sport getSport(long id) {
		return getHibernateTemplate().get(Sport.class, id);
	}

	@Override
	public void setSport(Sport sport) {
		getHibernateTemplate().saveOrUpdate(sport);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Sport> getAll() {
		return getHibernateTemplate().findByNamedQuery("getAllSport");
	}

	@Override
	public void delSport(Sport sport) {
		getHibernateTemplate().delete(sport);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Sport> getSportByType(String type) {
		return (List<Sport>) getHibernateTemplate().findByNamedQueryAndNamedParam("getSportByType", "type", type);
	}
	
}
